#include <buola/net/cxmlrpcarray.h>
#include <buola/net/cxmlrpcstruct.h>
#include <buola/net/cxmlrpccall.h>

namespace buola { namespace io {

CXMLRPCArray::CXMLRPCArray()
{
}

CXMLRPCArray::CXMLRPCArray(CXMLRPCCall &pCall)
    :   mArray(pCall.XML().NewNode("array"))
{
    mData=mArray.NewChild("data");
}

CXMLRPCArray::CXMLRPCArray(xml::CNode pArray)
    :   mArray(pArray)
{
    mData=mArray.FirstChild("data");
}

int CXMLRPCArray::GetCount()
{
    return mData.ChildCount();
}

void CXMLRPCArray::Get(int n,CXMLRPCStruct &pStruct)
{
    xml::CNode lValue=mData.NthChild(n).FirstChild();
    if(!lValue.MatchesName("struct")) throw XInvalid("wrong type in XML_RPC array");
    pStruct=CXMLRPCStruct(lValue);
}

void CXMLRPCArray::Add(const CXMLRPCStruct &pStruct)
{
    mData.NewChild("value").Append(pStruct.XML());
}

void CXMLRPCArray::Add(const std::string &pValue)
{
    mData.NewChild("value").NewChild("string",pValue);
}

/*namespace io*/ } /*namespace buola*/ }
